package com.qj.yantaishan.controller;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.AdverCategory;
import com.qj.yantaishan.service.IAdverCategoryService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/AdverCategory")
public class AdverCategoryController extends BaseController
{
    private String prefix = "yantaishan/AdverCategory";

    @Autowired
    private IAdverCategoryService adverCategoryService;

    @RequiresPermissions("yantaishan:category:view")
    @GetMapping()
    public String category()
    {
        return prefix + "/category";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("yantaishan:category:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AdverCategory adverCategory)
    {
        startPage();
        List<AdverCategory> list = adverCategoryService.selectAdverCategoryList(adverCategory);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("yantaishan:category:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AdverCategory adverCategory)
    {
        List<AdverCategory> list = adverCategoryService.selectAdverCategoryList(adverCategory);
        ExcelUtil<AdverCategory> util = new ExcelUtil<AdverCategory>(AdverCategory.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("yantaishan:category:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AdverCategory adverCategory)
    {
        return toAjax(adverCategoryService.insertAdverCategory(adverCategory));
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("yantaishan:category:edit")
    @GetMapping("/edit/{catId}")
    public String edit(@PathVariable("catId") Long catId, ModelMap mmap)
    {
        AdverCategory adverCategory = adverCategoryService.selectAdverCategoryByCatId(catId);
        mmap.put("adverCategory", adverCategory);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("yantaishan:category:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AdverCategory adverCategory)
    {
        return toAjax(adverCategoryService.updateAdverCategory(adverCategory));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("yantaishan:category:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(adverCategoryService.deleteAdverCategoryByCatIds(ids));
    }
}
